<?php defined('SYSPATH') or die('No direct script access.');?>
{php echo Common::getCss('base.css,base_new.css'); }
{template 'stourtravel/public/public_min_js'}
{php echo Common::getScript("uploadify/jquery.uploadify.min.js,DatePicker/WdatePicker.js,choose.js,product_add.js,jquery.validate.js"); }
{php echo Common::getCss('uploadify.css','js/uploadify/'); }

<div class="container-page" {if !$date}style="height: 250px"{/if}>
    <form id="submit_frm">
        <ul class="info-item-block">
            {if !$date}
            <li>
                <span class="item-hd" style="width: 120px">日期范围：</span>
                <div class="item-bd">
                    <input type="text" id="start_time" name="start_time" class="input-text w150 choosetime" />
                    <span class="item-text pl-5 pr-5 c-999">—</span>
                    <input type="text" id="end_time"  name="end_time"  class="input-text w150 choosetime" />
                </div>
            </li>
            <li>
                <span class="item-hd">库存日期：</span>
                <div class="item-bd">
                    <div class="date-scope-container">
                        <div class="ds-tab-nav">
                            <label class="radio-label">
                                <input type="radio" name="number_rule" value="1" checked />全部日期范围
                            </label>
                            <label class="radio-label ml-50">
                                <input type="radio" name="number_rule" value="2" />日期范围下的星期
                            </label>
                            <label class="radio-label ml-50">
                                <input type="radio" name="number_rule" value="3" />日期范围下的天
                            </label>
                        </div>
                        <div class="ds-tab-box mt-10 clearfix tab-box-3" style="display: none">
                            <?php  for ($i=1;$i<=31;$i++)
                            {
                                echo " <span class='item' data-id='$i'>$i</span>"  ;
                            }
                            ?>
                        </div>
                        <div class="ds-tab-box mt-10 clearfix tab-box-2" style="display: none">
                            <span class="item" data-id="1">星期一</span>
                            <span class="item" data-id="2">星期二</span>
                            <span class="item" data-id="3">星期三</span>
                            <span class="item" data-id="4">星期四</span>
                            <span class="item" data-id="5">星期五</span>
                            <span class="item" data-id="6">星期六</span>
                            <span class="item" data-id="7">星期天</span>
                        </div>
                    </div>
                </div>
            </li>
            {/if}
            <li>
                <span class="item-hd">库存：</span>
                <div class="item-bd">
                    <label class="radio-label mt-2">
                        <input type="radio" {if $number=='-1'}checked="checked"{/if} name="number_type" value="1">不限
                    </label>
                    <span class="item-text" style="height: 31px">
                        <label class="radio-label ml-30" >
                            <input type="radio" {if $number!='-1'}checked="checked"{/if} name="number_type" value="2">数量
                        </label>
                        <input type="text" value="{$number}" id="number" {if $number=='-1'}style="display: none"{/if} name="number" class="reset-input input-text w100 ml-5 va-t" onkeyup="this.value=this.value.replace(/\D/g,'')"/>
                    </span>
                </div>
            </li>
        </ul>
        <div id="hidevalue" class="hide">
        </div>
        <input type="hidden" name="suit_id" value="{$suit_id}">
        <input type="hidden" name="type_id" value="{$type_id}">
        <input type="hidden" name="date" value="{$date}">
    </form>

</div>
<div class="clearfix text-c mt-20">
    <a href="javascript:;" id="cancel-btn" class="btn btn-grey-outline  radius">取消</a>
    <a href="javascript:;" class="btn btn-primary radius ml-10">确定</a>
</div>
<script>
    $(function () {
        //切换库存方式
        $('input[name=number_type]').change(function () {
            var number_type = $(this).val();
            if(number_type==1)
            {
                $('#number').hide();
            }
            else
            {
                $('#number').show();
            }
            $("#number").valid();
        });

        //日历选择
        $("#start_time").click(function(){
            WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',minDate:'%y-%M-%d',maxDate: '#{%y+2}-%M-%d'})
        });
        $("#end_time").click(function(){
            WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'end_time\')}',maxDate: '#{%y+2}-%M-%d'})
        });

        //日期方式切换
        $('input[name=number_rule]').change(function () {
            var type = $(this).val();
            $('.tab-box-3').hide();
            $('.tab-box-2').hide();
            if(type==2)
            {
                $('.tab-box-2').show();
            }
            if(type==3)
            {
                $('.tab-box-3').show();
            }
        });
        //星期选择
        $(".tab-box-2 span").click(function(e) {
            var v=$(this).data('id');
            if($(this).hasClass('on'))
            {
                $("#week_val_"+v).remove();
            }
            else
            {
                $("#hidevalue").append("<input type='hidden' id='week_val_"+v+"' name='week_val[]' value='"+v+"'/>");
            }
            $(this).toggleClass('on');

        });
        //具体到天
        $(".tab-box-3 span").click(function(e) {

            var v=$(this).data('id');
            v=$.trim(v);
            v=window.parseInt(v);
            if($(this).hasClass('on'))
            {
                $("#month_val_"+v).remove();
            }
            else
            {
                $("#hidevalue").append("<input type='hidden' id='month_val_"+v+"' name='month_val[]' value='"+v+"'/>");
            }
            $(this).toggleClass('on');
        });

        //切换库存方式
        $('input[name=store]').change(function () {
            var store = $(this).val();
            if(store==1)
            {
                $('#number').hide();
            }
            else
            {
                $('#number').show();
            }
        });

        //确定
        $('.btn-primary').click(function () {
            var data = $('#submit_frm').serialize();
            var date = $("[name='date']").val();
            if(date){
                set_single_number(data);
                return false;
            }
            $.ajax({
                data: data,
                dataType: 'json',
                type: 'post',
                url: '/newtravel/price/ajax_save_all_number',
                success: function (data) {
                    if(data.status){
                        ST.Util.showMsg(data.msg,4,1000);
                        setTimeout(function(){
                            ST.Util.responseDialog(data,true);
                        },1000)
                    }else{
                        ST.Util.showMsg(data.msg,5,1000);
                    }
                }
            })
        });

        //取消
        $('#cancel-btn').click(function () {
            var data = $('#submit_frm').serialize();
            ST.Util.responseDialog({data:data},false);
        })
    })
    function set_single_number(data)
    {
        $.ajax({
            data: data,
            dataType: 'json',
            type: 'post',
            url: '/newtravel/price/ajax_save_single_number',
            success: function (data) {
                if(data.status){
                    ST.Util.showMsg(data.msg,4,1000);
                    setTimeout(function(){
                        ST.Util.responseDialog(data,true);
                    },1000)
                }else{
                    ST.Util.showMsg(data.msg,5,1000);
                }
            }
        })
    }
</script>